package demo6;

import java.util.HashMap;
import java.util.HashSet;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-07-31
 * Time: 21:46
 */
class Solution {
    public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
        HashMap<Integer,Integer> map = new HashMap<>();
        //统计nums1和nums2进行相加的数字出现的次数
        for(int i =0;i<nums1.length;++i){
            for(int j = i;j<nums2.length;++j){
                map.put(nums1[i]+nums2[j],map.getOrDefault(nums1[i]+nums2[j],0)+1);
            }
        }
        int count =0;
        for(int i =0;i<nums3.length;++i){
            for(int j = i;j<nums4.length;++j){
                int ret = 0-(nums3[i]+nums4[j]);
                if(map.containsKey(ret)){
                    count += map.get(ret);
                }
            }
        }
        return count;
    }
}
public class TestDemo {
    public static void main(String[] args) {
        Solution solution = new Solution();
        // [2,7,11,15], target = 9
        int[] nums1 = {-1,-1};
        int[] nums2 ={-1,1};
        int[] nums3 ={-1,1};
        int[] nums4 = {1,-1};
        //
        solution.fourSumCount(nums1,nums2,nums3,nums4);

    }

}
